package com.trsvax.gwthello.client.gwtui.widgets;

import com.google.gwt.dom.client.Element;
import com.google.gwt.i18n.client.Dictionary;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.RootPanel;

public class SlideShowWidget extends Composite {
	String id;
	Dictionary dictionary;
	Element e;

	String[] urls;
	Integer counter = -1;
	Boolean loop = false;

	public SlideShowWidget(String id, Dictionary dictionary) {
		Button button = new Button();
		this.dictionary = dictionary;
		this.id = id;
		e = RootPanel.get(id).getElement();
		urls = new String[2];
		urls[0] = "http://www.judypaul.com/shop/viewpaintings.imageproduct:displayimage/2686976?t:ac=229376";
		urls[1] = "http://www.judypaul.com/shop/viewpaintings.imageproduct:displayimage/2686987";
		schedule(3000);

		initWidget(button);

	}

	void schedule(Integer intraval) {
		Timer t = new Timer() {
			@Override
			public void run() {
				if (++counter >= urls.length) {
					if (!loop) {
						this.cancel();
						return;
					}
					counter = 0;
				}
				e.setAttribute("src", urls[counter]);
			}
		};
		t.scheduleRepeating(intraval);
	}
}
